﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KillBill.Common.View;
using KillBill.Presentation.Common;
using KillBill.Presentation.Modules.Products.IView;
using KillBill.Presentation.Modules.Products.ProductsServiceReference;
using KillBill.Presentation.Modules.Products.View;

namespace KillBill.Presentation.Modules.Products.Presenter
{
    public class ProductMainPresenter
    {
        private ProductsServiceClient _productsService;

        public IProductMain View { get; set; }

        public ProductMainPresenter(IProductMain view)
        {
            _productsService = new ProductsServiceClient();
            View = view;
        }

        public void LoadProductList()
        {
            try
            {
                var result = _productsService.GetProductList(Context.SessionID);
                if (!result.Success && result.Messages != null && result.Messages.Count > 0)
                    View.ShowMessage(View.Text, result.Messages[0], MessageOptions.Ok,
                                         MessageIcon.Error);
                else
                    View.ProductList = result.Products;
            }
            catch (Exception ex)
            {
                View.ShowMessage(View.Text, ex.Message, MessageOptions.Ok,
                                 MessageIcon.Error);
            }
        }

        public void ShowProductAddView()
        {
            var form = new ProductAddEditView();
            form.ShowDialog();
        }

        public void ShowProductEditView()
        {
            var form = new ProductAddEditView(View.CurrentProduct);
            form.ShowDialog();
        }


    }
}
